<template>
  <el-card shadow="never">
    <template #header>
      <div class="card-header">
        <span>菜品总览</span>
        <el-button type="primary" link @click="navigateTo('/dish')">查看菜品</el-button>
      </div>
    </template>
    <div class="overview-grid">
      <div class="data-item">
        <p class="tit">已启售</p>
        <p class="num">{{ dishesData.sold || 0 }}</p>
      </div>
      <div class="data-item">
        <p class="tit">已停售</p>
        <p class="num">{{ dishesData.discontinued || 0 }}</p>
      </div>
      <div class="button-item">
        <el-button type="primary" @click="navigateTo('/dish/add')">新增菜品</el-button>
      </div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';

interface IOverview {
  sold?: number;
  discontinued?: number;
}

withDefaults(defineProps<{
  dishesData: IOverview
}>(), {
  dishesData: () => ({})
});

const router = useRouter();
const navigateTo = (path: string) => router.push(path);
</script>

<style lang="scss" scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  span {
    font-size: 16px;
    font-weight: 600;
  }
}

.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.data-item {
  .tit {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
  }
  .num {
    font-size: 24px;
    font-weight: bold;
  }
}

.button-item {
  justify-self: center;
}
</style>
